const mongoose=require('mongoose')
const DB_URL='mongodb://localhost:27017/coco-tea'
mongoose.connect(DB_URL)

const models={
  user_table:{
    'user':{type:String,require:true},
    'pwd':{type:String,require: true},
    'username':{type:String},
    'desc':{type:String}
  },
  token_table:{
    'token':{type:String,require:true},
    'userId':{type:mongoose.Schema.ObjectId,require:true},
    'expired':{type:Date}
  },
  kind_table:{
    'name':{type:String,require:true}
  },
  product_table:{
    'name':{type:String,require:true},
    'kind_id':{type:mongoose.Schema.ObjectId,require:true},
    'des':{type:String},
    'pic':{type:String}
  }
}
for(let m in models){
  mongoose.model(m,mongoose.Schema(models[m]))
}

module.exports={
  getModel:function(name) {
    return mongoose.model(name)
  }
}
